
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author B1367
 */
public class xmlTry {
    public static void main(String args[]){
        try {
            DocumentBuilder DOMBldr = DocumentBuilderFactory.newInstance().newDocumentBuilder();
            Document DOM = DOMBldr.parse(new File("C:\\test.xml"));
            NodeList databases = DOM.getElementsByTagName("database");
            int totdbs = databases.getLength();
            for (int i = 0; i < totdbs; i++){
                    Element db = (Element) databases.item(i);
                    String dbname = db.getAttribute("name");
                    String engine = db.getAttribute("engine");
                    String authen = engine.equalsIgnoreCase("mssql") ? db.getAttribute("authen") : "sql";
                    String hostnm = db.getAttribute("host");
                    String usernm = db.getAttribute("user");
                    String userpw = db.getAttribute("password");
                    System.out.println(db.getTagName() + ":: [" + authen + "]" + usernm + ":" + userpw + "@" + engine + "://" + hostnm + "/" + dbname);

            }
            
        } catch (SAXException ex) {
            Logger.getLogger(xmlTry.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(xmlTry.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ParserConfigurationException ex) {
            Logger.getLogger(xmlTry.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}
